﻿using System;
using System.Globalization;
using System.Xml.Serialization;
using Pospa.NET.WebPageTestApi.Interfaces;

namespace Pospa.NET.WebPageTestApi.DataObjects
{
	[Serializable]
	[XmlRoot("response")]
	public class TestStatus : BaseTestResponse, ITestStatus
	{
		private const string DateTimeFormat = "MM/dd/yy H:mm:ss";

		[XmlIgnore]
		public string TestId
		{
			get { return Data.TestId; }
		}

		[XmlIgnore]
		public int Runs
		{
			get { return Data.Runs; }
		}

		[XmlIgnore]
		public bool FvOnly
		{
			get { return Data.FvOnly.Equals(1); }
		}

		[XmlIgnore]
		public string Location
		{
			get { return Data.Location; }
		}

		[XmlIgnore]
		public DateTime? StartTime
		{
			get
			{
				if (string.IsNullOrEmpty(Data.StartTime))
				{
					return null;
				}
				return DateTime.ParseExact(Data.StartTime, DateTimeFormat, CultureInfo.InstalledUICulture.DateTimeFormat);
			}
		}

		[XmlIgnore]
		public long Elapsed
		{
			get { return Data.Elapsed; }
		}

		[XmlIgnore]
		public DateTime? CompleteTime
		{
			get
			{
				if (String.IsNullOrEmpty(Data.CompleteTime))
				{
					return null;
				}
				return DateTime.ParseExact(Data.CompleteTime, DateTimeFormat, CultureInfo.InstalledUICulture.DateTimeFormat);
			}
		}

		[XmlElement("data")]
		public TestStatusData Data { get; set; }
	}

	[Serializable]
	[XmlRoot("data")]
	public class TestStatusData
	{
		[XmlElement("testId")]
		public string TestId { get; set; }

		[XmlElement("runs")]
		public int Runs { get; set; }

		[XmlElement("fvonly")]
		public int FvOnly { get; set; }

		[XmlElement("location")]
		public string Location { get; set; }

		[XmlElement("startTime")]
		public string StartTime { get; set; }

		[XmlElement("elapsed")]
		public long Elapsed { get; set; }

		[XmlElement("completeTime")]
		public string CompleteTime { get; set; }
	}
}